import React from 'react'
import type { EventEmitter } from 'ahooks/es/useEventEmitter'
import type { ChatItem } from '@/types/app'

export type ChatContextValue = {
  sendText: (text: string) => void
  eventEmitter: EventEmitter<{ type: string;data: ChatItem }>
}

export const ChatContext = React.createContext<ChatContextValue>({
  sendText: (_t) => {},
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  // @ts-expect-error
  eventEmitter: null,
})

export const useChatContext = () => {
  return React.useContext(ChatContext)
}
